package com.ol.edu.server.service.course.impl;


import com.ol.edu.server.entity.Course;
import com.ol.edu.server.entity.CourseLesson;
import com.ol.edu.server.entity.CourseSection;
import com.ol.edu.server.mapper.CourseContentMapper;
import com.ol.edu.server.service.course.CourseContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Roger
 * @date 2020/9/6 14:44
 * @description
 */
@Service

public class CourseContentServiceImpl implements CourseContentService {

    @Autowired
    private CourseContentMapper courseContentMapper;
    /*
        根据课程ID查询章节与课时信息
     */
    @Override
    public List<CourseSection> findSectionAndLesson(Integer courseId) {
        List<CourseSection> sectionList = courseContentMapper.findSectionAndLesson(courseId);

        return sectionList;
    }
    /*
        回显章节对应的课程信息
     */
    @Override
    public Course findCourseByCourseId(Integer courseId) {
        Course course = courseContentMapper.findCourseByCourseId(courseId);
        return course;
    }
    /*
        保存章节信息
     */
    @Override
    public void saveSection(CourseSection section) {
        courseContentMapper.saveSection(section);
    }
    /*
        修改章节信息
     */
    @Override
    public void updateSection(CourseSection section) {
        courseContentMapper.updateSection(section);
    }
    /*
        修改章节状态
     */
    @Override
    public Map<String, Integer> updateSectionStatus(Integer id, Integer status) {
        CourseSection courseSection = new CourseSection();
        courseSection.setId(id);
        courseSection.setStatus(status);

        Integer res = courseContentMapper.updateSectionStatus(courseSection);
        //返回1表示修改成功
        if (res == 1) {
            Map<String, Integer> map = new HashMap<>(1);
            map.put("status", status);
            return map;
        }
        return null;
    }
    /*
        保存课时信息
     */
    @Override
    public void saveLesson(CourseLesson lesson) {
        courseContentMapper.saveLesson(lesson);

    }

    @Override
    public void updateLession(CourseLesson lesson) {
        courseContentMapper.updateLession(lesson);
    }
}
